package com.ruoyi.medicalPSys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.medicalPSys.domain.Xiangmufenlei;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.medicalPSys.domain.Xiangmuxinxi;
import com.ruoyi.medicalPSys.service.IXiangmuxinxiService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目信息Controller
 * 
 * @author ruoyi
 * @date 2024-04-22
 */
@Api("项目信息")
@RestController
@RequestMapping("/medicalInfo/medicalInfo")
public class XiangmuxinxiController extends BaseController
{
    @Autowired
    private IXiangmuxinxiService xiangmuxinxiService;

    /**
     * 查询项目信息列表
     */
    @ApiOperation("查询项目信息列表")
    @GetMapping("/list")
    public TableDataInfo list(Xiangmuxinxi xiangmuxinxi)
    {
        startPage();
        List<Xiangmuxinxi> list = xiangmuxinxiService.selectXiangmuxinxiList(xiangmuxinxi);
        for (int i = 0; i <list.size() ; i++) {
            Xiangmuxinxi xiangmuxinxi1 = list.get(i);
            System.out.print(xiangmuxinxi1.getXiangmufenleiId());
        }
        return getDataTable(list);
    }
    /**
     * 前端项目分类下拉列表获取
     */
    @ApiOperation("获取项目名称下拉框")
    @GetMapping("/selectXiangmuMC")
    public TableDataInfo getXiangmuMingCen()
    {
        Xiangmuxinxi xiangmuxinxi1 = new Xiangmuxinxi();
        List<Xiangmuxinxi> list = xiangmuxinxiService.selectXiangmuxinxiList(xiangmuxinxi1);
        return getDataTable(list);
    }

    /**
     * 导出项目信息列表
     */
    @PreAuthorize("@ss.hasPermi('medicalInfo:medicalInfo:export')")
    @Log(title = "项目信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Xiangmuxinxi xiangmuxinxi)
    {
        List<Xiangmuxinxi> list = xiangmuxinxiService.selectXiangmuxinxiList(xiangmuxinxi);
        ExcelUtil<Xiangmuxinxi> util = new ExcelUtil<Xiangmuxinxi>(Xiangmuxinxi.class);
        util.exportExcel(response, list, "项目信息数据");
    }

    /**
     * 获取项目信息详细信息
     */
    @ApiOperation("获取项目信息详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(xiangmuxinxiService.selectXiangmuxinxiById(id));
    }

    /**
     * 新增项目信息
     */
    @PreAuthorize("@ss.hasPermi('medicalInfo:medicalInfo:add')")
    @Log(title = "项目信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Xiangmuxinxi xiangmuxinxi)
    {
        return toAjax(xiangmuxinxiService.insertXiangmuxinxi(xiangmuxinxi));
    }

    /**
     * 修改项目信息
     */
    @PreAuthorize("@ss.hasPermi('medicalInfo:medicalInfo:edit')")
    @Log(title = "项目信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Xiangmuxinxi xiangmuxinxi)
    {
        return toAjax(xiangmuxinxiService.updateXiangmuxinxi(xiangmuxinxi));
    }

    /**
     * 删除项目信息
     */
    @PreAuthorize("@ss.hasPermi('medicalInfo:medicalInfo:remove')")
    @Log(title = "项目信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(xiangmuxinxiService.deleteXiangmuxinxiByIds(ids));
    }
}
